package com.zwr.mvpdemo.base;

import java.lang.ref.Reference;
import java.lang.ref.WeakReference;

/**
 * 弱引用View 防止内存泄漏
 * @param <T>
 */
public abstract class BasePresenter<T> {

    protected Reference<T> mViewrRef    ;

    public void attachView(T view){
        mViewrRef = new WeakReference<>(view);
    }

    protected T getView(){
        return mViewrRef.get();
    }

    public boolean isAttachView(){
        return  null != mViewrRef && null != mViewrRef.get();
    }

    public void  detachView(){
        if(null != mViewrRef){
            mViewrRef.clear();
            mViewrRef = null;
        }
    }
}
